---
--- @class SimulatorManager
SimulatorManager = ClientFight.CreateClass("SimulatorManager")
local this = SimulatorManager
ClientFight.SimulatorManager = SimulatorManager;
--- @public
--- @return SimulatorManager
---@type DataManager
---@type DataManagerTest
ClientFight.DataManagerTest = ClientFight.DataManagerTest;
--[[
* 创建成员
*
* @param memberId
* @param memberParams  <br/>
* memberParams[0] 英雄ID <br/>
* memberParams[1] 等级   <br/>
* memberParams[2] 星级   <br/>
* memberParams[3] 初始能量     <br/>
* memberParams[4] 最大血量 填5W，表示血量就是5W        <br/>
* memberParams[5] 属性模板编号 0表示无模板             <br/>
* memberParams[6] 攻增加万分比 填0表示不用修正(跟副本怪物计算方式不同)     <br/>
* memberParams[7] 防增加万分比 填0表示不用修正(跟副本怪物计算方式不同)     <br/>
* memberParams[8] 血增加万分比 填0表示不用修正(跟副本怪物计算方式不同)     <br/>
* @return
*/]]
addOverload(SimulatorManager, "createTeamMember", function(memberId, site, ...)
    local memberParams = ...;
    local heroId = memberParams[1];
    local level = memberParams[2];
    local star = memberParams[3];
    local energy = memberParams[4];
    local maxHp = memberParams[5];
    local monsterTid = memberParams[6];
    local addAttackRatio = memberParams[7];
    local addDefenseRatio = memberParams[8];
    local weaponlv = memberParams[9];
    local addskillId = 0;
    local skillLv = 0;
    if type(memberParams) == "table" then
        if (table.getn(memberParams) > 9) then
            addskillId = memberParams[10];
            skillLv = memberParams[11];
        end
    end
    local t_heroBean = ClientFight.DataManager.t_heroBeanMap[heroId] or {};
    local t_levelupattributeBean = ClientFight.DataManagerTest.t_levelupattributeBeanMap[tostring(level * 100)] or {};
    local t_herorankupcoBean = ClientFight.DataManagerTest.t_herorankupcoBeanMap[tostring(star)]or {};
    local t_monstertempletBean = ClientFight.DataManagerTest.t_monstertempletBeanMap[tostring(monsterTid)] or {};

    -- member
    local member = ClientFight.TeamMember.New();
    member.partnerId = memberId;
    member.partnerModelId = heroId;
    member.level = level;
    member.star = star;
    member.site = site;
    member.initEnergy = energy;
    member.initHp = maxHp;
    member.weaponLevel = weaponlv;
    -- 属性
    local attrs = {};
    -- 基础属性
    local baseAttributes = t_heroBean.f_CharacterValue;
    if baseAttributes ~= nil then
        for i, attribute in pairs(baseAttributes) do

            local attrType = attribute[1];
            local attrValue = attribute[2];
            if attrType == FighterAttributeEnum.ATK.id then
                attrValue = attrValue * toRatio(t_levelupattributeBean.f_Para);
                attrValue = attrValue * toRatio(t_herorankupcoBean.f_RankUpCo);
                attrValue = attrValue + (attrValue * toRatio(addAttackRatio));
            end

            if attrType == FighterAttributeEnum.HP.id then
                attrValue = (attrValue * toRatio(t_levelupattributeBean.f_Para));
                attrValue = (attrValue * toRatio(t_herorankupcoBean.f_RankUpCo));
                attrValue = attrValue + (attrValue * toRatio(addDefenseRatio));
            end
            if attrType == FighterAttributeEnum.DEF.id then
                attrValue = (attrValue * toRatio(t_levelupattributeBean.f_Para));
                attrValue = (attrValue * toRatio(t_herorankupcoBean.f_RankUpCo));
                --                        attrValue +=  (attrValue * toRatio(addMapHpRatio));
            end
            attrs[attrType] = attrValue;
        end

    end

    -- 怪物模板增加属性
    local monsterAttributes = t_monstertempletBean.f_MonsterValueTemplet;
    if t_monstertempletBean ~= nil then
        if monsterAttributes ~= nil then
            for i, attribute in pairs(monsterAttributes) do

                local attrType = attribute[1];
                local attrValue = attribute[2];

                local oldValue = attrs[attrType];
                local oldValue = attrs[attrType] or 0;
                attrs[attrType] = oldValue + attrValue;
            end
        end
        -- 怪物模板技能
        if (t_monstertempletBean.f_MonsterSkill ~= nil) then
            for i, skillId in pairs(t_monstertempletBean.f_MonsterSkill) do

                member.addSkills[skillId] = skillId;
            end
        end
    end
    if (addskillId > 0) then
        member.addSkills[addskillId] = addskillId;
        local skillTemplate = dataManager.getMajorSkillTemplate(addskillId, skillLv);
        if (skillTemplate ~= nil) then
            local value = {};
            value[DynamicParam.DMP] = skillTemplate.attr .. "";
            member.getBuffDynamicParam().put(skillTemplate.buffId, value);
        end
    end
    if (maxHp > 0) then
        attrs[FighterAttributeEnum.HP.id] = maxHp + 0;
    end
    member.attributeMap[CalculatorTypeEnum.BASE] = attrs;

    return member;
end, "number", "number", "...")

addOverload(SimulatorManager, "createTeamMember", function(memberId, site, heroId)
    return this.createTeamMember(memberId, site,
            heroId, 300, 100, 1000, 100000000, 0, 0, 0, 0);
end, "number", "number", "number")
--[[
* 创建队伍
*/]]
addOverload(SimulatorManager, "createTeam", function(teamId, gladiatorIndex)
    local gladiatorTeamBean = ClientFight.DataManagerTest.t_gladiatorteamBeanList[tostring(gladiatorIndex)];
    if (gladiatorTeamBean == nil) then
        --throw new RuntimeException("T_gladiatorTeam template no found, index: " + gladiatorIndex);
    end
    local baseMemberId = 100 * teamId;
    local team = ClientFight.Team.New();
    team.supportSkillId = gladiatorTeamBean.f_SupportSkillId;
    if (gladiatorTeamBean.f_GladiatorPara1 ~= nil and gladiatorTeamBean.f_GladiatorPara1 ~= "") then
        baseMemberId = baseMemberId + 1;
        local monster = this.createTeamMember(baseMemberId, 1, gladiatorTeamBean.f_GladiatorPara1);
        table.insert(team.members, monster);
    end
    if (gladiatorTeamBean.f_GladiatorPara2 ~= nil and gladiatorTeamBean.f_GladiatorPara2 ~= "") then
        baseMemberId = baseMemberId + 1;
        local monster = this.createTeamMember(baseMemberId, 2, gladiatorTeamBean.f_GladiatorPara2);
        table.insert(team.members, monster);
    end
    if (gladiatorTeamBean.f_GladiatorPara3 ~= nil and gladiatorTeamBean.f_GladiatorPara3 ~= "") then
        baseMemberId = baseMemberId + 1;
        local monster = this.createTeamMember(baseMemberId, 3, gladiatorTeamBean.f_GladiatorPara3);
        table.insert(team.members, monster);
    end
    if (gladiatorTeamBean.f_GladiatorPara4 ~= nil and gladiatorTeamBean.f_GladiatorPara4 ~= "") then
        baseMemberId = baseMemberId + 1;
        local monster = this.createTeamMember(baseMemberId, 4, gladiatorTeamBean.f_GladiatorPara4);
        table.insert(team.members, monster);
    end
    if (gladiatorTeamBean.f_GladiatorPara5 ~= nil and gladiatorTeamBean.f_GladiatorPara5 ~= "") then
        baseMemberId = baseMemberId + 1;
        local monster = this.createTeamMember(baseMemberId, 5, gladiatorTeamBean.f_GladiatorPara5);
        table.insert(team.members, monster);
    end
    if (gladiatorTeamBean.f_GladiatorPara6 ~= nil and gladiatorTeamBean.f_GladiatorPara6 ~= "") then
        baseMemberId = baseMemberId + 1;
        local monster = this.createTeamMember(baseMemberId, 6, gladiatorTeamBean.f_GladiatorPara6);
        table.insert(team.members, monster);
    end

    return team;
end, "number", "number")

addOverload(SimulatorManager, "createTeam", function(teamId, heroIds, supportSkillId)
    local team = Team.New();
    team.supportSkillId = supportSkillId;
    local baseMemberId = 100 * teamId;
    for i = 1, table.getn(heroIds) do
        if (heroIds[i] ~= 0) then
            baseMemberId = baseMemberId + 1;
            local member = this.createTeamMember(baseMemberId, i + 1, heroIds[i]);
            table.insert(team.members, monster);
        end
    end
    return team;
end, "number", "table", "number")

addOverload(SimulatorManager, "createBattleInfo", function(fightId, team0, team1, randSeed)

    local battleInfo = BattleInfo.New();
    battleInfo.fightId = fightId;
    battleInfo.atkTeam = team0;
    battleInfo.defTeam = team1;
    battleInfo.randSeed = tostring(randSeed);
    return battleInfo;
end, "number", "table", "table", "number")
addOverload(SimulatorManager, "createBattleInfo", function(fightId, attackers, defenders, randSeed, attackerSupportSkillId, defSupportSkillId)

    return this.createBattleInfo(fightId,
            this.createTeam(0, attackers, attackerSupportSkillId),
            this.createTeam(1, defenders, defSupportSkillId),
            randSeed);
end, "number", "table", "table", "number", "number", "number")

addOverload(SimulatorManager, "createBattleInfo", function(fightId, attackerGladiatorIndex, defenderGladiatorIndex, randSeed)
    return this.createBattleInfo(fightId, this.createTeam(0, attackerGladiatorIndex), this.createTeam(1, defenderGladiatorIndex), randSeed);
end, "number", "number", "number", "number")



